package cn.shengongying.service.impl;

import cn.shengongying.dao.UserDiscountInfoMapper;
import cn.shengongying.model.UserDiscountInfo;
import cn.shengongying.service.IUserDiscountInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户优惠券信息 服务实现类
 * </p>
 *
 * @author RXK
 * @since 2022-01-10
 */
@Service
public class UserDiscountInfoServiceImpl extends ServiceImpl<UserDiscountInfoMapper, UserDiscountInfo> implements IUserDiscountInfoService {

    private final UserDiscountInfoMapper userDiscountInfoMapper;

    public UserDiscountInfoServiceImpl(UserDiscountInfoMapper userDiscountInfoMapper) {
        this.userDiscountInfoMapper = userDiscountInfoMapper;
    }

    @Override
    public List<UserDiscountInfo> findByUserId(Long userId) {
        return userDiscountInfoMapper.selectList(new LambdaQueryWrapper<UserDiscountInfo>().eq(UserDiscountInfo::getUserId,userId));
    }

    @Override
    public void updateStatus(Long id, int status) {
        UserDiscountInfo info = new UserDiscountInfo();
        info.setId(id);
        info.setStatus(status);
        userDiscountInfoMapper.updateById(info);
    }

    @Override
    public void newUser(Long userId) {
        List<UserDiscountInfo> infoList = UserDiscountInfo.newUser(userId);
        super.saveBatch(infoList);
    }
}
